//
//  HRNewFriendsRequestListCell.m
//  Hear
//
//  Created by mac on 2017/10/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRNewFriendsRequestListCell.h"
#import "HRCoverImageModel.h"
@interface HRNewFriendsRequestListCell ()
@property(nonatomic, strong)UIImageView *iconImageView;
@property(nonatomic, strong)UILabel *descLabel;
@property(nonatomic, strong)UIButton *agreeButton;

@end
@implementation HRNewFriendsRequestListCell

-(void)setNotiModel:(HRDynamicNotificationModel *)notiModel{
    WeakSelf
    if (notiModel.iconColor.length){
        [HRCoverImageModel OriginImage:[UIImage imageNamed:notiModel.icon] scaleToSize:CGSizeMake(40, 40) callBackOriginImage:^(UIImage *originImage) {
            weakSelf.iconImageView.image = originImage;
        }];
        self.iconImageView.backgroundColor = [UIColor colorWithHexString:notiModel.iconColor];
    }else{
        [self.iconImageView.layer setImageWithURL:[NSURL URLWithString:notiModel.icon] placeholder:[UIImage imageNamed:@""]];
    }
    
    self.descLabel.text = notiModel.message;
    
    if ([notiModel.isFriend integerValue]){
        self.agreeButton.enabled = NO;
        [self.agreeButton setTitle:@"已同意" forState:0];
        [self.agreeButton setTitleColor:SecondTextColor forState:0];
    }else{
        self.agreeButton.enabled = YES;
        [self.agreeButton setTitle:@"同意" forState:0];
        [self.agreeButton setTitleColor:MainColor forState:0];
    }
    
}


+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HRNewFriendsRequestListCell";
    
    HRNewFriendsRequestListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        cell = [[HRNewFriendsRequestListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        CGFloat pading = 15;

        
        self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(pading, pading, 40, 40)];
        self.iconImageView.layer.cornerRadius = self.iconImageView.width/2;
        self.iconImageView.clipsToBounds = YES;
        [self addSubview:self.iconImageView];
        
        self.descLabel = [UILabel new];
        self.descLabel.font = CustomUIFont(14);
        self.descLabel.textColor = FirstTextColor;
        [self  addSubview:self.descLabel];
        self.descLabel.frame = CGRectMake(self.iconImageView.right+pading, self.iconImageView.top, kFullWidth-self.iconImageView.right*2-pading, self.iconImageView.height);
        self.descLabel.numberOfLines = 2;
        
        
        UIButton *agreeButton = [UIButton buttonWithType:0];
        [agreeButton setTitle:@"同意" forState:0];
        [agreeButton setTitleColor:MainColor forState:0];
        agreeButton.titleLabel.font = CustomUIFont(14);
        [agreeButton addTarget:self action:@selector(agreeButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:(self.agreeButton=agreeButton)];
        agreeButton.frame = CGRectMake(kFullWidth-60, self.iconImageView.top, 60, self.iconImageView.height);
//        agreeButton.layer.borderColor = CustomColor(240, 240, 240, 1).CGColor;
//        agreeButton.layer.borderWidth = 1;
//        agreeButton.layer.cornerRadius = 3;
//        agreeButton.clipsToBounds = YES;
        
        UILabel *lineLabel = [UILabel new];
        lineLabel.backgroundColor = CustomColor(240, 240, 240, 1);
        [self  addSubview:lineLabel];
        lineLabel.frame = CGRectMake(0, 69, kFullWidth, 1);
        
    }
    return self;
}

- (void)agreeButtonClick{
    if (self.agreeButtonBlock){
        self.agreeButtonBlock();
    }
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
